<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qmlscene.qdoc -->
  <title>Prototyping with qmlscene | Qt 5.12 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.12</a></td><td >Prototyping with qmlscene</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.12.3 参考指南</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#adding-module-import-paths">Adding Module Import Paths</a></li>
<li class="level1"><a href="#loading-test-data">Loading Test Data</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">用qmlscene进行原型化设计</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-qmlscene.html-description -->
<div class="descr"> <a name="details"></a>
<p>Qt 5包含<code>qmlscene</code>这是一个实用程序，可以在应用程序完成之前加载和显示QML文档。这个实用程序还提供了以下额外的功能，这些功能在开发QML应用程序时非常有用:</p>
<ul>
<li>在最大化窗口中查看QML文档。</li>
<li>以全屏模式查看QML文档。</li>
<li>使窗口透明。</li>
<li>禁用多式样(反锯齿)。</li>
<li>不要检测.qml文件的版本。</li>
<li>以慢动作运行所有动画。</li>
<li>将窗口大小调整为根项的大小。</li>
<li>添加导入路径列表。</li>
<li>添加一个命名包。</li>
<li>使用翻译文件设置语言。</li>
</ul>
<p><code>qmlscene</code>实用程序用于测试QML应用程序，而不是作为生产环境中的启动程序。要在生产环境中启动QML应用程序，请开发自定义c++应用程序或将QML文件打包到模块中。有关更多信息，请参见<a href="qtquick-deployment.html">部署QML应用程序</a>。</p>
<p>要加载.qml文件，运行工具并选择要打开的文件，或者在命令提示符上提供文件路径:</p>
<pre class="cpp">

  qmlscene myqmlfile<span class="operator">.</span>qml

</pre>
<p>要查看配置选项，请使用<code>-help</code> 参数运行<code>qmlscene</code>。</p>
<a name="adding-module-import-paths"></a>
<h2 id="adding-module-import-paths">添加模块导入路径</h2>
<p>可以使用code>-I</code>标志提供额外的模块导入路径。 例如，<a href="../qtqml/qtqml-qmlextensionplugins-example.html">QML插件示例</a>创建一个C++插件，该插件使用命名空间<code>TimeExample</code>标识。 要加载插件，你必须运行从例子的基本目录<code>qmlscene</code> 和 <code>-I</code> 标志:</p>
<pre class="cpp">

  qmlscene <span class="operator">-</span>I imports plugins<span class="operator">.</span>qml

</pre>
<p>这将当前目录添加到导入路径，以便<code>qmlscene</code>在<code>imports（导入）</code>目录中找到插件。</p>
<p><b>注意： </b>默认情况下，导入搜索路径中包含当前目录，但是除非显式添加路径，否则不会找到名称空间(如<code>TimeExample</code>）中的模块。</p><a name="loading-test-data"></a>
<h2 id="loading-test-data">Loading Test Data</h2>
<p>通常，QML应用程序的原型是测试数据，这些测试数据稍后会被C++插件中的实际数据源替换。<code>qmlscene</code>实用程序通过将测试数据加载到应用程序上下文中，在这方面提供了帮助。它在与目标QML文件相同的目录中查找一个名为<code>dummydata</code> 的目录，并将该目录中的. QML文件作为QML对象加载，并将它们作为以文件命名的属性绑定到根上下文。</p>
<p>例如，下面的QML文档引用了文档中不存在的<code>lottoNumbers</code>属性:</p>
<pre class="qml">

  import QtQuick 2.3

  <span class="type"><a href="../qtquick/qml-qtquick-listview.html">ListView</a></span> {
      <span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">300</span>
      <span class="name">model</span>: <span class="name">lottoNumbers</span>
      <span class="name">delegate</span>: <span class="name">Text</span> { <span class="name">text</span>: <span class="name">number</span> }
  }

</pre>
<p>如果在文档的目录中有一个包含<code>lottoNumbers.qml</code>文件的目录<code>dummydata</code>， qml文件如下:</p>
<pre class="qml">

  import QtQuick 2.3

  <span class="type"><a href="../qtqml/qml-qtqml-models-listmodel.html">ListModel</a></span> {
      <span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> { <span class="name">number</span>: <span class="number">23</span> }
      <span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> { <span class="name">number</span>: <span class="number">44</span> }
      <span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> { <span class="name">number</span>: <span class="number">78</span> }
  }

</pre>
<p>然后该模型将自动加载到前一个文档中的<a href="../qtquick/qml-qtquick-listview.html">ListView</a>中。</p>
<p>当从<code>dummydata</code>加载时，将包含子属性。下面的文档应用了<code>clock.time</code>属性：</p>
<pre class="qml">

  import QtQuick 2.3
  <span class="type"><a href="../qtquick/qml-qtquick-text.html">Text</a></span> { <span class="name">text</span>: <span class="name">clock</span>.<span class="name">time</span> }

</pre>
<p>文本值可以由<code>dummydata/clock.qml</code>填充，一个在根上下文中具有 <code>time</code>属性的qml文件:</p>
<pre class="qml">

  import QtQuick 2.3
  <span class="type"><a href="../qtqml/qml-qtqml-qtobject.html">QtObject</a></span> { property <span class="type"><a href="../qtqml/qml-int.html">int</a></span> <span class="name">time</span>: <span class="number">54321</span> }

</pre>
<p>要用实际数据替换它，可以使用 <a href="../qtqml/qqmlcontext.html#setContextProperty">QQmlContext::setContextProperty</a>(). 将实际数据对象绑定到C++中的根上下文。这将在 <a href="../qtqml/qtqml-cppintegration-topic.html">集成QML和c++时</a>里详细介绍。</p>
</div>
<!-- @@@qtquick-qmlscene.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
